﻿using Common.Communal;
using ERP.Domain.Scheduling;
using MediatR;
using Scheduling.Api.Read.Application.Command.TeamCommand;
using SqlSugar;

namespace Scheduling.Api.Read.Application.CommandHandlers.TeamHandler
{
    public class TeamTypeCreateCommandHandler : IRequestHandler<TeamTypeCreateCommand, ApiResult<List<TeamType>>>
    {
        public TeamTypeCreateCommandHandler(ISqlSugarClient sqlSugar)
        {
            SqlSugar = sqlSugar;
        }

        public ISqlSugarClient SqlSugar { get; }

        public Task<ApiResult<List<TeamType>>> Handle(TeamTypeCreateCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<TeamType>> result = new ApiResult<List<TeamType>>();
            result.Code = EnumCode.Ok;
            result.Message = "班组类型显示成功";
            
            // 查询所有未删除的班组类型
            var list = SqlSugar.Queryable<TeamType>()
                .Where(x => x.IsDelete == false)
                .ToList();
            
            result.Data = list;
            return Task.FromResult(result);
        }
    }
}
